﻿using Abp.Authorization;
using Abp.UI;
using Microsoft.AspNetCore.Mvc;
using SOEI.Solution.Application.Contracts.CommonOthers.BarCode;
using SOEI.Solution.Application.Contracts.CommonOthers.BarCode.Dtos;
using SOEI.Solution.Application.Contracts.Customized.WaterImage;
using SOEI.Solution.CommonOthers.BarCode.DomainService;
using SOEI.Solution.CommonOthers.BarCode.StructEntities;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace SOEI.Solution.CommonOthers.BarCode
{
    [ApiExplorerSettings(GroupName = "Manager", IgnoreApi = false)]
    public class BarCodeAppService : SolutionAppServiceBase, IBarCodeAppService
    {
        public readonly IBarCodeManager _manager; 

        public BarCodeAppService(IBarCodeManager manager)
        {
            _manager = manager;
        }

        /// <summary>获取二维码图片
        /// </summary>
        public async Task<FileContentResult> GetBarCodeImage(BarCodeInputDto input)
        {
            var vParam = ObjectMapper.Map<BarCodeParam>(input);

            byte[] vData = await _manager.GetBarCodeImage(vParam);

            return new FileContentResult(vData, "image/png");
        }

        /// <summary>获取二维码图片Base64字符串
        /// </summary>
        public async Task<string> GetBarCodeImageBase64(BarCodeInputDto input)
        {
            var vContent = await GetBarCodeImage(input);

            return Convert.ToBase64String(vContent.FileContents);
        }

        /// <summary>创建二维码
        /// </summary>
        public async Task CreateBarCode(BarCodeInputDto input)
        {
            var vParam = ObjectMapper.Map<BarCodeParam>(input);

            await _manager.CreateBarCode(vParam);
        }

       
    }
}
